package thread;

import java.util.Stack;

public class Consumer implements Runnable {
	private Stack<Integer> pool;

	public Consumer(Stack<Integer> pool) {
		super();
		this.pool = pool;
	}

	@Override
	public void run() {
		while (true) {
			synchronized (pool) {

				if (!pool.isEmpty()) {
					int m = pool.pop();
					System.out.println("consumer is consuming..." + m);
					pool.notify();
				} else {
					System.out.println("Is Empty.....");
					try {
						pool.wait();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
